<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>内容管理</title>
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
 <link href="/res/third/powerFloat/css/powerFloat.css" rel="stylesheet" type="text/css" />
 <script src="/res/third/powerFloat/js/mini/jquery-powerFloat-min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/res/common/js/moment.min.js"></script>
<style>


</style>
<script type="text/javascript">
	function goback() {
		top.addTab('集采供应商管理','/member/member_list.do','icon-maxcdn');
	}
$(function() {

    $("#startdate").datebox({
        formatter: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + m + '-' + d;
        },
        onSelect: function (dateselect) {
            //enddate清空
            $('#enddate').datebox('setValue', '');
            $("#enddate").datebox("calendar").calendar({
                validator: function (date) {
                    return dateselect <= date;
                }
            });
        }
    });

    $("#enddate").datebox({
        formatter: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + m + '-' + d;
        }
    })

    $(".trigger4").powerFloat({
        targetMode: "ajax",
        targetAttr: "rel",
        position: "1-4"
    });
    
    $("#memberForm").submit(function(){
    	var mobile=/^1[3-9]\d{9}$/;
    	var phone=$("#phone").val();
    	if(!mobile.test(phone)){
    		alert("电话格式错误");
    		return false;
    	}
    	var company=$("#companyId").val();
    	if(company.trim()==""){
    		alert("公司不能为空");
    		return false;
    	}
    	var startdate=$("[name='signintime']").val();
    	var enddate=$("[name='endtime']").val();
    	if((startdate==""||startdate==null)||(enddate==""||enddate==null)){
    		alert("时间不能为空");
    		return false;
    	}else{
    		    var flag;
	    		art.dialog.post({
					  
					type : "post",
					dataType : "json",
					async: false,
					url : "/member/validateSameMem.do",
					data : {mid:$("#companyId").val(),startdate:startdate},
					success : function(data) {
						 if(!data.success){
							 alert(data.msg);
							 flag=false;
						 }else{
							 flag=true;
						 }
					}
			 
			},"数据正在验证.... ");
	    	return flag;
    	}
    });
    
})

var dialogAddCom;
function chooseCompany(){
	dialogAddCom = art.dialog({
	        title: "选择供应商",
	        lock:true,
	        content: document.getElementById('providerDiv')
	    });
	initProvider(1);
}

function initProvider(pageNo,so_customerinfo){
	 //alert(pageNo);
	 art.dialog.post({
			url : '/member/providerCompany.do',
			type : 'post',
			dataType : 'json',
			data : {
				pageNo : pageNo,so_customerinfo:so_customerinfo
			},
			beforeSend:function(){
	            art.dialog.tips("处理中...");
	        },
			success : function(data){
				if(data.success){
					$("#ftr").nextAll().remove();
					var companyList=data.attributes.companyList;
					for (var i = 0; i < companyList.length; i++) {
						var time=companyList[i].registertime;
						if(time==null){
							time='';
						}
						$("#companyTab").append("<tr>"
											        +"<td>"+companyList[i].id+"</td>"
											        +"<td style='cursor: pointer;' onclick='sendBackCName("+companyList[i].id+",\""+companyList[i].companyName+"\" )' >"+companyList[i].companyName+"</td>"
											        +"<td>"+(time != '' ? moment(time).format('YYYY-MM-DD HH:mm') : "") +"</td>"
											   +"</tr>");
						
					}
					
					$("#pageTotal").val(data.attributes.totalPage);
					$("#pageNo").val(data.attributes.pageNo);
					$("#so_customerinfo_back").val(data.attributes.so_customerinfo)
				}else{
					error_msg(data.msg , function(){location.reload();});
				}
			}
	 
	},"数据初始化中.... ");
	 
}

function sendBackCName(cid,cname){
	 $("#companyName").val(cname);
	 $("#companyId").val(cid);
	 dialogAddCom.close();
}
function searchProvider(){
	var so_customerinfo=$("#so_customerinfo").val();
	initProvider(1,so_customerinfo);
}

function pageUp(){
	var pageNo=$("#pageNo").val();
	pageNo=parseInt(pageNo);
	if(pageNo!=1){
		 pageNo=pageNo-1;
	}
	var so_customerinfo=$("#so_customerinfo_back").val();
	initProvider(pageNo,so_customerinfo);
}
function pageNext(){
	var pageNo=$("#pageNo").val();
	var pageTotal=$("#pageTotal").val();
	pageNo=parseInt(pageNo);
	if(pageNo!=pageTotal){
		 pageNo=pageNo+1;
	}
	var so_customerinfo=$("#so_customerinfo_back").val();
	initProvider(pageNo,so_customerinfo);
}
</script>
</head>
<body>
<!-- 新建 -->
	   <div class="panel panel-info">
	        <div class="panel-heading">
	          <h3 class="panel-title">添加集采供应商</h3>
	        </div>
        <div class="panel-body" style="overflow: hidden;border-bottom: none;">
			<form class="form-horizontal" role="form" action="/member/savemember.do"  id="memberForm">
			  <div class="form-group" style="margin-top:15px;">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>供应商名称</label>
			    <div class="col-sm-5">
			      <input type="text"  placeholder="请选择供应商名称" name="companyName" id="companyName" required="required" readonly="readonly">
			      <input type="hidden" id="companyId" name="companyId">
			      <button type="button" class="btn btn-info btn-xs delbtn" onclick="chooseCompany()">选择供应商</button>
			    </div>
			  </div>
			  <div class="form-group" >
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>签约时间</label>
			    <div class="col-sm-5">
			      <input  name="signintime" id="startdate" style="width:120px;"  >
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>结束时间</label>
			    <div class="col-sm-2">
			      <input  name="endtime"   id="enddate"     style="width:120px;"  >
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>集采联系人</label>
			    <div class="col-sm-2">
			      <input type="text" class="form-control" id="contacts" placeholder="集采联系人" name="contacts" required >
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label"><span style="color:red;">*</span>联系人电话</label>
			    <div class="col-sm-2">
			        <input type="text" class="form-control" id="phone" placeholder="联系电话" name="phone" required>
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <div class="col-sm-offset-2 col-sm-10">
			      <!--  
			      <button type="button" class="btn btn-info" onclick="validateForm();">提交</button>
			      -->
			      <input type="submit" class="btn btn-info" value="提交">
			      &nbsp;&nbsp;&nbsp;&nbsp;
			      <button type="button" class="btn btn-primary" onclick="goback();">返回</button>
			    </div>
			  </div>
			</form>
        </div>
      </div>
      
      <div style="display: none;width: 600px;" id="providerDiv">
      		<div style="border: 1px solid #ddd;padding-bottom: 8px;">
      			<div>
      				<input style="display: inline-block;width: 160px;height: 30px;margin: 8px;" type="text" class="form-control" id="so_customerinfo" placeholder="请输入供应商名称" name="so_customerinfo">
      				<button type="button" class="btn btn-info btn-xs delbtn" onclick="searchProvider()">查询</button>
      			</div>
      			<table class="table table-hover table-bordered table-striped table-condensed" id="companyTab" style="margin-bottom: 8px;">
					
						<tr id="ftr">
							<th width="10%">序号</th>
							<th width="70%">供应商名称</th>
							<th width="20%">入驻时间</th>
						</tr>
					
				</table>
				<div style="text-align: right;padding-right: 8px;">
					<button type="button" class="btn btn-primary btn-xs delbtn" onclick="pageUp()">上一页</button>
					<button type="button" class="btn btn-primary btn-xs delbtn" onclick="pageNext()">下一页</button>
				</div>
      		</div>
      		<input id="pageNo" type="hidden" value="1">
      		<input id="pageTotal" type="hidden">
      		<input id="so_customerinfo_back" type="hidden">
      </div>
</body>
</html>

